/*********************************************************************
 * Módulo 3. Tutorial de desarrollo con NME. Clase Premio. 
 * Programación Multimedia y Juegos
 * Autor: David Vallejo Fernández    david.vallejo@tegnix.com
 * Autor: Carlos González Morcillo   carlos.gonzalez@tegnix.com
 *
 * You can redistribute and/or modify this file under the terms of the
 * GNU General Public License ad published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * and later version. See <http://www.gnu.org/licenses/>.
 *
 * This file is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.  
 *********************************************************************/

package graphics.sprites;

import aze.display.TileLayer;

class Prize extends NonPlayer {
  var _speed:Int;     // Velocidad de movimiento
  var _deltaY:Int;    // Desplazamiento en vertical

  // Constructor =====================================================
  public function new(id:String, layer:TileLayer, w:Int, h:Int, 
		      spw:Int, sph:Int, speed:Int) {
    super(id, layer, w, h);
    _speed = speed + 1;
    _deltaY = Std.random(5) + 1;
    y = Std.int(sph/2.0 + Std.random(Std.int(h - sph)));
    x = Std.int(w + spw);
  }

  // Actualización ===================================================
  public override function update(w:Int, h:Int, eTime:Int):Bool {
    x-= _speed;
    y += _deltaY;
    rotation += _speed * 0.002;

    if (y < height /2) { // Rebote superior
      y = height/2;
      _deltaY *= -1;
    }

    if (y > h - height /2) { // Rebote superior
      y = h - height/2;
      _deltaY *= -1;
    }
    
    return (isInside());
  }

}